(function($){
	$.ShowPopWindow=function(option)
	{
		option = $.extend({
			title: "标题",
			html:null,
			closeBtn:null,
			closeFun:null,
			submitBtn:null,
			submitFun:null
		}, option || {});
		
		var html='<div class="popblock"><dl><dt><span>'+option.title+'</span><a href="javascript:;" title="关闭">关闭</a></dt><dd id="popDd"></dd></dl></div>';
		var bgDiv=document.createElement("DIV");
        var selfObj=$(".popblock");
        if(selfObj.length==0)
        {
            $("body").append(html);
            selfObj=$(".popblock");
        }
		
		$("#popDd").html(option.html);
		
        $("body").append(bgDiv);
        $(bgDiv).css({position:"absolute",width:$(document).width(), height:$(document).height(),top:"0",left:"0",opacity:0.8,background:"#fff",display:"none","z-index":100});
		
        $.windowCenter(selfObj);
        selfObj.show();
        $(bgDiv).show();
        $(bgDiv).bgiframe();
        $(bgDiv).click(function(){
            $(bgDiv).remove();
            selfObj.css({display:"none"});
			if(option.closeFun)
               option.closeFun.call(this);
        });
		
		$("dt a",selfObj).click(function(){
            $(bgDiv).remove();
            selfObj.css({display:"none"});
			if(option.closeFun)
               option.closeFun.call(this);
        });
		
		if(option.closeBtn)
		{
			$(option.closeBtn).click(function(){
				$(bgDiv).remove();
				selfObj.css({display:"none"});
				if(option.closeFun)
				   option.closeFun.call(this);
			});
		}
		
		if(option.submitBtn)
		{
			$(option.submitBtn).click(function(){
				$(bgDiv).remove();
				selfObj.css({display:"none"});
				if(option.submitFun)
				   option.submitFun.call(this);
			});
		}
		
		$(window).scroll(function(){
			if(selfObj.css("display") != "none")
			{
				$.windowCenter(selfObj);
				$(bgDiv).css({width:$(document).width(), height:$(document).height()});
			}
		});
	}
	
	$.windowCenter=function(obj)
	{
		var windowWidth=$.support.cssFloat ? window.innerWidth : document.documentElement.clientWidth;
		var windowHeight=$.support.cssFloat ? window.innerHeight : document.documentElement.clientHeight;
		var objWidth=obj.width();
		var objHeight=obj.height();
		var objTop=(windowHeight - objHeight ) / 2 + $.getBodyScrollTop();
		var objLeft=(windowWidth - objWidth ) / 2;
		obj.css({position:"absolute",display:"block","z-index":1000,top:objTop,left:objLeft});
		obj.bgiframe();
	}
	
	$.getBodyScrollTop=function(){
        var scrollPos; 
        if (typeof window.pageYOffset != 'undefined') { 
            scrollPos = window.pageYOffset; 
        } 
        else if (typeof document.compatMode != 'undefined' && 
            document.compatMode != 'BackCompat') { 
            scrollPos = document.documentElement.scrollTop; 
        } 
        else if (typeof document.body != 'undefined') { 
            scrollPos = document.body.scrollTop; 
        } 
        return scrollPos;
    }
	
	$.searchSite = function(key,list){
		var keywords = $(key).val();
		var sele = $(list);
		
		$.ajax({
			url: APP+"?"+VAR_MODULE+"=Site&"+VAR_ACTION+"=getSites",
			cache: false,
			data:{"key":keywords},
			dataType:"json",
			success:function(data)
			{
				if(data && data.length > 0)
				{
					sele.empty();
					
					option = new Option("==选择==",0);
					sele.get(0).options.add(option);
					
					for(var i=0;i<data.length;i++)
					{
						option = new Option(data[i].name, data[i].id);
						sele.get(0).options.add(option);
					}
				}
			}
		});	
	}
	
	$.searchGoods = function(key,list){
		var keywords = $(key).val();
		var sele = $(list);
		
		sele.empty();
		option = new Option("搜索中...","");
		sele.get(0).options.add(option);
		
		$.ajax({
			url: APP+"?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=getGoodsList",
			cache: false,
			data:{"key":keywords},
			dataType:"json",
			success:function(data)
			{
				sele.empty();
				if(data && data.length > 0)
				{	
					for(var i=0;i<data.length;i++)
					{
						var name = "";
						
						if(data[i].city != "")
							name = "【"+data[i].site_name+" "+data[i].city+"】"+data[i].name;
						else
							name = "【"+data[i].site_name+"】"+data[i].name;
							
						option = new Option(name, data[i].id);
						sele.get(0).options.add(option);
					}
				}
				else
				{
					option = new Option("未搜索到相关团购","");
					sele.get(0).options.add(option);
				}
			}
		});	
	}
	
	$.searchUser = function(key,list,is_site){
		var keywords = $(key).val();
		var sele = $(list);
		
		sele.empty();
		option = new Option("搜索中...",0);
		sele.get(0).options.add(option);
		
		$.ajax({
			url: APP + '?m=User&a=getUserList',
			cache: false,
			data:{"key":keywords,"is_site":is_site},
			dataType:"json",
			success:function(data)
			{
				sele.empty();
				if(data && data.length > 0)
				{	
					for(var i=0;i<data.length;i++)
					{
						option = new Option(data[i].user_name, data[i].id);
						sele.get(0).options.add(option);
					}
				}
				else
				{
					option = new Option("未搜索到相关会员",0);
					sele.get(0).options.add(option);
				}
			}
		});	
	}
	
	$.timeConvs = function(d,h,m,s,t)
	{
		var date = new Date();
		var nowTime = date.getTime();
		var dTime = parseInt($(d).val()) * 86400000;
		var hTime = parseInt($(h).val()) * 3600000;
		var mTime = parseInt($(m).val()) * 60000;
		var sTime = parseInt($(s).val()) * 1000;
		
		var endTime = nowTime + dTime + hTime + mTime + sTime;
		var endDate = new Date(endTime);
		
		var year = endDate.getFullYear();
		var month = endDate.getMonth()+1;
		if(month < 10)
			month = "0"+ month;
			
		var date1 = endDate.getDate();
		if(date1 < 10)
			date1 = "0"+ date1;
			
		var hours = endDate.getHours();
		if(hours < 10)
			hours = "0"+ hours;
			
		var minutes = endDate.getMinutes();
		if(minutes < 10)
			minutes = "0"+ minutes;
			
		var seconds = endDate.getSeconds();
		if(seconds < 10)
			seconds = "0"+ seconds;
		
		var timeStr = year + "-" + month + "-" + date1 +" "+ hours +":"+minutes+":"+seconds;
		$(t).val(timeStr);
	}
})(jQuery);